package com.lan.app.api;


import com.lan.app.repository.Tp;
import com.lan.app.service.ITpService;
import com.lan.support.page.Page;
import com.lan.support.page.PageHelper;
import com.lan.support.response.json.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("api/tp")
public class TpApi {

    @Resource
    private ITpService ctpService;


    @ResponseBody
    @RequestMapping(value = "list")
    public R list(Tp tp, PageHelper helper) {
        Page<Tp> page = ctpService.page(helper, tp);
        return R.OK(page);
    }

    @ResponseBody
    @RequestMapping(value = "add")
    public R add(Tp tp) {
        Integer id = ctpService.save(tp);
        return R.OK(id);
    }

    @ResponseBody
    @RequestMapping(value = "del/{id}")
    public R del(@PathVariable Integer id) {
        ctpService.del(id);
        return R.OK();
    }

    @ResponseBody
    @RequestMapping(value = "update")
    public R update(Tp tp) {
        ctpService.updateById(tp);
        return R.OK();
    }

    @ResponseBody
    @RequestMapping(value = "detail/{id}")
    public R detail(@PathVariable Integer id) {
        Tp ctp = ctpService.get(id);
        return R.OK(ctp);
    }


    @ResponseBody
    @RequestMapping("tp")
    public R tp(@RequestParam Integer tdId) {
        List<Tp> list = ctpService.getList(tdId);
        return R.OK(list);
    }
}
